package com.colis.quartz.common.base;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * <p> 描述： </p>
 *
 * @author wlp
 * @version 1.0.0
 * @date 2021/12/6 16:35
 */
@Data
@ApiModel("分页参数")
public class PageParam implements Serializable {

    @ApiModelProperty(value = "页码，从 1 开始", required = true, example = "1")
    @NotNull(message = "页码不能为空")
    @Min(value = 1, message = "页码最小值为 1")
    private Integer pageIndex;

    @ApiModelProperty(value = "每页条数，最大值为 1000", required = true, example = "10")
    @NotNull(message = "每页条数不能为空")
    private Integer pageSize;

    @ApiModelProperty(value = "开始行数")
    private int offset;

    public int getOffset() {
        return null == pageIndex ? 0 : (pageIndex - 1) * pageSize;
    }

    public Integer getPageIndex() {
        return this.pageIndex - 1;
    }
}
